CREATE OR REPLACEFUNCTION testIOTime() RETURNS VOID AS
$BODY$
DECLARE primarykeysarray integer[] = '{}';
DECLARE numQueries integer := 10000;
DECLARE starttime:=now();
BEGIN
	
	-- create if not exists io results table
	IF NOT EXISTS(
		SELECT * FROM io_results_table WHERE id =1
		) THEN
			CREATE TABLE IF NOT EXISTS io_results_table(
				id SERIAL PRIMARY KEY,
				numqueries INTEGER,
				numpkeys INTEGER,
				start_time timestamp,
				end_time timestamp
			);
	END IF;
	
	SELECT INTO primarykeysarray aid
	FROM pgbench_accounts ORDER BY RAND() LIMIT numQueries
		
	--FOREACH i IN ARRAY primarykeysarray	
	--LOOP
	--	select abalance from pgbench_accounts where aid=:aid
	--ENDLOOP;
	
	-- insert into new results table
	INSERT INTO io_results_table VALUES(numQueries, array_length(primarykeysarray, 1), starttime,now());

END;
$BODY$
LANGUAGE 'plpgsql'

SELECT $testIOTime();
